#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
const string LABEL = "ABCDE";
struct Edge {
    int x, y;
} E[] = {
        {0, 1},//A->B
        {0, 2},//A->C
        {2, 4},//C->E
        {1, 3},//B->D
        {2, 1},//C->B

};
const int maxn = 100 + 50;//最大顶点数
const int maxm = maxn * maxn;//最大边数量

int dis[maxn][maxn];//图的距离(关联）矩阵存储
int n = LABEL.length(), m;//点的数量和边的数量
int ind[maxn];//入度表
int path[maxn];//如果存在拓扑排序，存储拓扑排序结果
int book[maxn];

/**
 * 拓扑排序算法
 * 1. 计算每一个定点的出入度表
 * 2. 把入度为0的所有点加入队列中
 * 只要队列不空，重复如下操作
 * 3. 从队列中出队一个元素
 * 4. 更新出入度表
 * 5. 把入度为0的所有点加入队列中
 *
 * 算法输出字典序最小的拓扑排序
 * @return
 */
bool Topsort() {
    queue<int> Q;
    int j = 0;
    for (int i = 0; i < n; i++) {
        if (ind[i] == 0 && book[i] == 0) {
            Q.push(i);
            book[i] = true;
        }
    }
    while (!Q.empty()) {
        int h = Q.front();
        path[j++] = h;
        Q.pop();
        for (int i = 0; i < n; i++) {
            if (dis[h][i] > 0) {
                --ind[i];
                if (ind[i] == 0 && book[i] == 0) {
                    Q.push(i);
                    book[i] = true;
                }
            }
        }
    }
    return j == n;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    for (auto e: E) {
        ind[e.y]++;
        dis[e.x][e.y] = 1;//有一条有向边 e.x->e.y
    }
    copy(ind + 0, ind + n, ostream_iterator<int>(cout, " "));
    cout << endl;
    cout << Topsort() << endl;
    cout << "path:";
    copy(path, path + n, ostream_iterator<int>(cout, " "));
    cout << endl;
    return 0;
}
